/*!
 * \file iptools_parse_portrange.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    char *dotted = (char *)frstrdup((char *)"10-20");
    u_short sport = 0;
    u_short dport = 0;

    iptools_parse_portrange(dotted, &sport, &dport);

    frfree(dotted);
    CU_ASSERT_EQUAL(sport,10);
    CU_ASSERT_EQUAL(dport,20);
    return;
}

static void __case2(void)
{
    char *dotted = NULL;
    u_short sport = 0;
    u_short dport = 0;

    iptools_parse_portrange(dotted, &sport, &dport);

    frfree(dotted);
    CU_ASSERT_EQUAL(sport,0);
    CU_ASSERT_EQUAL(dport,0);
    return;
}

static void __case3(void) {
    char *dotted = (char *)frstrdup((char *)"10");
    u_short sport = 0;
    u_short dport = 0;

    iptools_parse_portrange(dotted, &sport, &dport);

    frfree(dotted);
    CU_ASSERT_EQUAL(sport, 10);
    CU_ASSERT_EQUAL(dport, 10);
    return;

}

int add_suite_iptools_parse_portrange(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frsutl iptools_parse_portrange()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);



    return FR_SUCC;
}
